<?php

/**
 * Novost form.
 *
 * @package    dnevnik
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class NovostForm extends BaseNovostForm
{
  public function configure()
  {
     $this->widgetSchema['slika'] = new sfWidgetFormInputFile();

     $this->validatorSchema['slika'] = new sfValidatorFile();
  }

  protected function doSave ( $con = null )
  {
    $upload = $this->getValue('slika');

    if ( $upload )
    {
      $filename = $upload->getOriginalName();
      $filepath = 'images/novosti/'.$filename;

      $oldfilepath = 'images/novosti/'.$this->getObject()->getSlika();
      if ( strlen($this->getObject()->getSlika()) > 0 and file_exists($oldfilepath) )
      {
        unlink($oldfilepath);
      }
$upload->path = 'C:\wamp\www\dnevnik\web\\';
      echo $upload->save($filepath);var_dump($upload); die();
    }

    $delete = $this->getValue('slika_delete');
    if ( $delete )
    {
      $filename = $this->getObject()->getSlika();
      $filepath = 'images/novosti/'.$filename;
      @unlink($filepath);
      $this->getObject()->setSlika(null);
    }

    return parent::doSave($con);
  }

  public function updateObject($values = null)
  {
    $object = parent::updateObject($values);
    $object->setSlika(str_replace('images/novosti/', '', $object->getSlika()));
    return $object;
  }

}
